package com.lzx.iteam.widget;


import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;
import com.lzx.iteam.AttendanceSubClassExcleActivity;

public class CHScrollView extends HorizontalScrollView {

	private static final String TAG = "CHScrollView";

	public static boolean firstRight = true;
	public static boolean firstLeft = true;

	AttendanceSubClassExcleActivity activity;
	
	public CHScrollView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		activity = (AttendanceSubClassExcleActivity) context;
	}

	
	public CHScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
		activity = (AttendanceSubClassExcleActivity) context;
	}

	public CHScrollView(Context context) {
		super(context);
		activity = (AttendanceSubClassExcleActivity) context;
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		//进行触摸赋值
		activity.mTouchView = this;
		return super.onTouchEvent(ev);
	}
	
	@Override
	protected void onScrollChanged(int l, int t, int oldl, int oldt) {
		//当当前的CHSCrollView被触摸时，滑动其它
		if(activity.mTouchView == this) {
			int  maxScrollX = getChildAt(0).getMeasuredWidth()-getMeasuredWidth();
			if (getScrollX() == 0 ) { //滑到最左
				if (firstLeft){
					activity.onScrollLeft();
				}
				firstLeft = false;
				Log.d(TAG, "turn  left "  );
			}else if (getScrollX() == maxScrollX) {  //滑到最右
				if (firstRight){
					activity.onScrollRight();
				}
				firstRight = false;
			}else{
				activity.onScrollChanged(l, t, oldl, oldt);
			}
		}else{
			super.onScrollChanged(l, t, oldl, oldt);
		}
	}

}
